import 'package:flutter/material.dart';

import '../../../../helper/utils/util.dart';
import 'index.dart';

class LanguagePage extends GetView<LanguageController> {
  const LanguagePage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    return ListView.builder(
      itemBuilder: (ctx, idx) {
        var t = LocalizationStrings.types[idx];
        return InkWell(
          onTap: () {
            if (LocalizationStrings.type != t) {
              LocalizationStrings.type = t;
              Get.offAllNamed(RouterPath.main);
            }
          },
          child: Container(
            height: 50.r,
            color: Colors.white,
            padding: EdgeInsets.symmetric(horizontal: 12.r),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  LocalizationStrings.typeForKey(t),
                  style: TextStyle(
                    color: const Color(0xff333333),
                    fontSize: 15.sp,
                  ),
                ),
                LocalizationStrings.typeObs.value == t
                    ? Icon(
                        Icons.check,
                        color: ColorsUtil.theme,
                        size: 20.r,
                      )
                    : const SizedBox(),
              ],
            ),
          ),
        );
      },
      itemCount: LocalizationStrings.types.length,
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LanguageController>(
      builder: (_) {
        return Scaffold(
          appBar: detailAppBar(context, title: '语言设置'),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
